package Lambda;

import java.util.ArrayList;
import java.util.List;

public class buildLambdaClass {

    public void buildFun(double field_01,double field_02){
        System.out.println("buildFun Start");

        LambdaClassService01 lambdaClassService01=()->{
            return new LambdaClass();
        };
        System.out.println(lambdaClassService01.getLambdaClass().toString());

        LambdaClassService02 lambdaClassService02=(f1,f2)->{
            return new LambdaClass(f1,f2);
        };
        System.out.println(lambdaClassService02.getLambdaClass(field_01,field_02).toString());

        LambdaClassService01 lambdaClassService001 =LambdaClass::new;
        System.out.println(lambdaClassService001.getLambdaClass().toString());

        LambdaClassService02 lambdaClassService002 =LambdaClass::new;
        System.out.println(lambdaClassService002.getLambdaClass(field_01,field_02).toString());

        System.out.println("buildFun End");
    }

    public void sortFun(){
        System.out.println("sortFun Start");

        List<LambdaClass> lambdaClassLists =new ArrayList<>();

        lambdaClassLists.add(new LambdaClass(11,2));
        lambdaClassLists.add(new LambdaClass(54,2));
        lambdaClassLists.add(new LambdaClass(27,2));
        lambdaClassLists.add(new LambdaClass(72,2));
        lambdaClassLists.add(new LambdaClass(19,2));

        lambdaClassLists.sort((o1,o2)-> (int) (o1.getField_01()- (int)o2.getField_01()));
        System.out.println(lambdaClassLists);

        lambdaClassLists.forEach(System.out::println);

        LambdaClassGetFun(1,2,(f1, f2) -> f1+f2);



        System.out.println("sortFun End");
    }

    interface LambdaClassService01{
        LambdaClass getLambdaClass();
    }

    interface LambdaClassService02{
        LambdaClass getLambdaClass(double field_01,double field_02);
    }

    public void LambdaClassGetFun(double f1,double f2,LambdaClassInterface l){
        System.out.println("LambdaClassGetFun Start");
        System.out.println(l.p1(f1, f2));
        System.out.println("LambdaClassGetFun End");
    }

    @FunctionalInterface
    public interface LambdaClassInterface{
        double p1(double f1,double f2);
    }
}
